package org.study.influxdb.boot.config;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * InfluxDB 配置类
 *
 * @author LENOVO
 */
@Data
@Configuration
public class InfluxDbConfig {
    @Value("${spring.influx.url:''}")
    private String url;
    /**
     * You can generate an API token from the "API Tokens Tab" in the UI
     */
    @Value("${spring.influx.token:''}")
    private String token;

    @Value("${spring.influx.org:''}")
    private String org;

    @Value("${spring.influx.bucket:''}")
    private String bucket;

    @Value("${spring.influx.username:''}")
    private String username;

    @Value("${spring.influx.password:''}")
    private String password;

    @Bean
    public InfluxDBClient influxDBClient() {
        InfluxDBClient client = InfluxDBClientFactory.create(this.url, token.toCharArray());
        return client;
    }
}
